layui.extend({
    baseConfig : "/js/pages/baseConfig"
})
layui.use(['form','layer','laydate','table','laytpl','element','util','baseConfig'],function(){

    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        baseConfig = layui.baseConfig,
        $ = layui.jquery;
    //绑定校验
    form.verify({
        name : function(val){
            if(val == ''){
                return "备份名称不能为空";
            }
        }
    })

    /*
    //备份文件 上传
    upload.render({
        elem: '#filePathBtn',
        url: '/file/upload?type=backUpZipFile',
        method : "post",
        accept: "file",
        exts: "pdf",
        done: function(res, index, upload){ //上传后的回调
            $("input[name=filePath]").val( res.data.filePath);
        }
    }); */

    //监听提交
    form.on("submit(submitBtn)",function( data){
        //弹出loading
        var loadingIndex = top.layer.msg('系统数据备份中，请稍候', {icon: 16, time: false, shade: 0.8});
        //提交数据
        $.post("/systemRecord/backUp",{ "name" : data.field.name}, function (res) {
            top.layer.close( loadingIndex);
            if (res.code == 200) {
                setTimeout(function () {
                    top.layer.msg( res.msg);
                    layer.closeAll( "iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
            } else if (res.code == 60000) {
                top.layer.msg( res.msg);
            } else {
                top.layer.msg( res.msg);
            }
        });
    });
});
